package cn.shenshen.shop.util;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Setter
@Getter
public class Result<T> implements Serializable {
    public static final int SUCCESS_CODE = 200;//成功码.
    public static final String SUCCESS_MESSAGE = "操作成功";//成功信息.
    public static final int ERROR_CODE = 500;//错误码.
    public static final String ERROR_MESSAGE = "系统异常";//错误信息.
    private int code;//状态码
    private String msg;//错误信息
    private T data;
    public Result(){}
    private Result(int code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static <T> Result<T> success(T data){
        return new Result(SUCCESS_CODE,SUCCESS_MESSAGE,data);
    }
    public static Result defaultError(){
        return new Result(ERROR_CODE,ERROR_MESSAGE,null);
    }

    public static Result error(CodeMsg codeMsg) {

        return new Result(codeMsg.getCode(),codeMsg.getMsg(),null);
    }

    public boolean hashError(){
        return this.getCode() != 200;
    }
}